clc; clear all; close all;
imag=imread("fig6.tif");
figure;
imshow(imag);
new_image=scale(imag,3,1,2,1);
figure;
imshow(new_image);
figure;
new_image2=scale(imag,1,3,1,2);
imshow(new_image2);
function [new_imag]=scale(image,h_new,h_old,w_new,w_old)
[n,m]=size(image);
h=n*h_new/h_old;
w=m*w_new/w_old;
new_imag=uint8(zeros(h,w));
for i=1:h
    for j=1:w
        x_old=round(j*w_old/w_new);
        if x_old==0
            x_old=1;
        end
        if x_old>m
            x_old=m;
        end
        y_old=round(i*h_old/h_new);
        if y_old==0
            y_old=1;
        end
        if y_old>n
            y_old=n;
        end
        new_imag(i,j)=image(y_old,x_old);
    end
end
end